package com.zhuiyun.educations.api.sysmenuback.controller;

import com.zhuiyun.educations.api.sysmenuback.entiy.SysMenuBack;
import com.zhuiyun.educations.api.sysmenuback.service.SysMenuBackService;
import com.zhuiyun.educations.common.response.CommonResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * @ClassName SysMenuBackController
 * @Description TODO
 * @Author MJL
 * @Date 2023/6/19 9:26
 **/
@RestController
@RequestMapping("/Menu")
public class SysMenuBackController {
    @Resource
    SysMenuBackService sysMenuBackService;
    /**
    * @Author MJL
    * @Description todo 根据登录信息获取显示左侧菜单栏
    * @Date 2023/6/19 9:30
    * @Return  * @param null
    */
    @GetMapping("/SysMenuList")
    public CommonResult SysMenuList(String userLoginName){
        return CommonResult.ok(sysMenuBackService.SysMenuList(userLoginName));
    }
    /**
    * @Author MJL
    * @Description todo 菜单表全查
    * @Date 2023/6/20 14:40
    * @Return  * @param null
    */
    @GetMapping("/SysMenuBackList")
    public CommonResult SysMenuBackList(SysMenuBack sysMenuBack){
        return CommonResult.ok(sysMenuBackService.SysMenuBackList(sysMenuBack));
    }
    /**
    * @Author MJL
    * @Description todo 新增目录
    * @Date 2023/6/20 18:06
    * @Return  * @param null
    */
    @PostMapping("/SysMenuDirectoryAdd")
    public CommonResult SysMenuDirectoryAdd(@RequestBody SysMenuBack sysMenuBack){
        int i = sysMenuBackService.SysMenuDirectoryAdd(sysMenuBack);
        if (i>0){
            return CommonResult.ok("添加菜单成功");
        }else {
            return CommonResult.error("添加菜单失败");
        }
    }
    /**
    * @Author MJL
    * @Description todo 菜单表新增子菜单
    * @Date 2023/6/20 19:02
    * @Return  * @param null
    */
    @PostMapping("/SysMenuSunAdd")
    public CommonResult SysMenuSunAdd(@RequestBody SysMenuBack sysMenuBack){
        int i = sysMenuBackService.SysMenuSunAdd(sysMenuBack);
        if (i>0){
            return CommonResult.ok("添加子菜单成功");
        }else {
            return CommonResult.error("添加子菜单失败");
        }
    }
    /**
    * @Author MJL
    * @Description todo 目录下拉菜单数据（父级名称）
    * @Date 2023/6/20 20:47
    * @Return  * @param null
    */
    @GetMapping("/MenuSelectList")
    public CommonResult MenuSelectList (String menuSelectLogotype){
        List<SysMenuBack> list = sysMenuBackService.MenuSelectList(menuSelectLogotype);
        if (list != null){
            return CommonResult.ok(list);
        }else {
            return CommonResult.error(9999,"父级名称获取失败");
        }
    }
    /**
    * @Author MJL
    * @Description todo 菜单表删除
    * @Date 2023/6/21 11:31
    * @Return  * @param null
    */
    @DeleteMapping("/SysMenuUpdateDelete")
    public CommonResult SysMenuUpdateDelete(Integer id) {
        int i = sysMenuBackService.SysMenuUpdateDelete(id);
        if (i>0){
            return CommonResult.ok("删除成功");
        }else {
            return CommonResult.error("删除失败");
        }
    }
    /**
    * @Author MJL
    * @Description todo 菜单表修改目录
    * @Date 2023/6/21 13:06
    * @Return  * @param null
    */
    @PutMapping("/SysMenuDirectoryUpdate")
    public CommonResult SysMenuDirectoryUpdate(@RequestBody SysMenuBack sysMenuBack){
        int i = sysMenuBackService.SysMenuDirectoryUpdate(sysMenuBack);
        if (i>0){
            return CommonResult.ok("修改成功");
        }else {
            return CommonResult.error("修改失败");
        }
    }
    /**
    * @Author MJL
    * @Description todo 菜单表修改子菜单
    * @Date 2023/6/21 14:39
    * @Return  * @param null
    */
    @PutMapping("/SysMenuSunUpdate")
    public CommonResult SysMenuSunUpdate(@RequestBody SysMenuBack sysMenuBack){
        int i = sysMenuBackService.SysMenuSunUpdate(sysMenuBack);
        if (i>0){
            return CommonResult.ok("修改子菜单成功");
        }else {
            return CommonResult.error("修改子菜单失败");
        }
    }
}
